using Holoville.HOTween;
using Holoville.HOTween.Core;
using UnityEngine;

public class rednessScreen : MonoBehaviour
{
	public UISprite sprite;

	public static rednessScreen inst;

	public int onRedScreenHP = 50;

	public float timeForHidePannel = 7f;

	private float pulsareAlpha;

	private void Awake()
	{
		inst = this;
	}

	private void Start()
	{
		HOTween.Init();
		if (sprite != null)
		{
			sprite.alpha = 0f;
		}
	}

	private void OnEnable()
	{
		PlayerBehavior.Redness += RednessScreen;
	}

	private void OnDisable()
	{
		PlayerBehavior.Redness -= RednessScreen;
	}

	private void RednessScreen(int health)
	{
		if (!(sprite == null))
		{
			if (health < onRedScreenHP && health > 0)
			{
				SetRedness(health);
				HOTween.Kill(sprite);
				Concealment();
			}
			if (health >= onRedScreenHP)
			{
				ResetMark();
				HideRedness();
			}
		}
	}

	private void Concealment()
	{
		if (!(pulsareAlpha > 0f))
		{
			return;
		}
		HOTween.To(sprite, 1f, new TweenParms().Prop("alpha", pulsareAlpha).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			pulsareAlpha -= 0.3f;
			HOTween.To(sprite, 3f, new TweenParms().Prop("alpha", pulsareAlpha).OnComplete((TweenDelegate.TweenCallback)delegate
			{
				pulsareAlpha += 0.2f;
				Concealment();
			}));
		}));
	}

	public void ResetMark()
	{
		HOTween.Kill(sprite);
		HOTween.To(sprite, 0f, new TweenParms().Prop("alpha", 0));
	}

	private void MaxRedness()
	{
		sprite.alpha = 1f;
	}

	public void HideRedness()
	{
		sprite.alpha = 0f;
	}

	private void SetRedness(int health)
	{
		pulsareAlpha = 1f - (float)health * 0.01f;
		sprite.alpha = pulsareAlpha;
	}
}
